package com.pocket.demo.core.log;

import ch.qos.logback.classic.pattern.ClassicConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;
import com.pocket.demo.base.system.PocketSystemInfo;

/**
 * logback 服务端口 格式转换器
 *
 * @author cookie.
 **/
public class ServerPortConverter extends ClassicConverter {
    public String convert(ILoggingEvent event) {
        return String.valueOf(getPort());
    }

    /**
     * 惊天大BUG！！！
     *      PocketSystemInfo.serverPort 定义为 Integer 类型，
     *      getPort() 返回的是 int 类型，
     *      当 PocketSystemInfo.serverPort 为空指针时，系统启动是输出卡死在
     *          Connected to the target VM, address: '127.0.0.1:53785', transport: 'socket'
     *      且无其他任何输出。。。。
     * @return
     */
    public static Integer getPort() {
        return PocketSystemInfo.serverPort;
    }
}
